package com.itheima.map;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class Demo05 {


    public static void main(String[] args) {
        Map<String, String> map = new HashMap<>();
        map.put("宝强","马蓉");
        map.put("宋喆","马蓉");
        map.put("乃亮","小璐");
        map.put("PGone","小璐");


        // keySet+ 迭代器
        Set<String> keySet = map.keySet();
        Iterator<String> iterator = keySet.iterator();
        while (iterator.hasNext()){
            String key = iterator.next();
            String value = map.get(key);
            System.out.println(key+"=="+value);
        }
    //   // keySet+ 增强for
        for (String key: keySet) {
            String value = map.get(key);
            System.out.println(key+"%%"+value);

        }
        //keySet+foreach
        keySet.forEach(key-> System.out.println(key+"@@"+map.get(key)));


        //entrySet+迭代器
        Set<Map.Entry<String, String>> entries = map.entrySet();
        Iterator<Map.Entry<String, String>> entryIterator = entries.iterator();
        while (entryIterator.hasNext()){
            Map.Entry<String, String> entry = entryIterator.next();
            System.out.println(entry.getKey()+"==="+entry.getValue());
        }
        //        //entrySet+增强for
        for (Map.Entry<String, String> entry : entries) {
            System.out.println(entry.getKey()+"---"+entry.getValue());
        }
        //entrySet+foreach
        entries.forEach(entry-> System.out.println(entry.getKey()+"---"+entry.getValue()));
    }
}
